package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import DB.DOUpdate;
import entity.student;

public class updateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public updateServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		
		int id = Integer.parseInt(request.getParameter("id"));
		String name = request.getParameter("name");
		String sex = request.getParameter("sex");
		String address = request.getParameter("address");
		String phone = request.getParameter("phone");
		String email = request.getParameter("email");
		
		student stu = new student();
		stu.setId(id);
		stu.setName(name);
		stu.setSex(sex);
		stu.setAddress(address);
		stu.setPhone(phone);
		stu.setEmail(email);
		
		DOUpdate doupdate = new DOUpdate();
		boolean flag = doupdate.updatestudent(stu);
		if(flag){
			response.sendRedirect("showStudent.jsp");
		}else{
			response.sendRedirect("failure.jsp");
		}
		
		
		
		
	}

}
